package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageDTO;
import com.sky.entity.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface DishMapper {


    //菜品分页查询->//根据分类id或name查询菜品
    List<DishVO> findList(DishPageDTO dishPageDTO);

    //菜品新增
    @AutoFill("insert")//自动填充
    @Options(useGeneratedKeys = true, keyProperty = "id")//主键返回
    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Dish dish);

    //回显菜品->根据id查菜品,批量删除->根据id查询菜品信息
    @Select("select d.*,c.name as categoryName from dish d left join category c on d.category_id = c.id where d.id = #{id}")
    DishVO findById(Long id);

    //修改菜品,->菜品的起售and禁售
    void update(Dish dish);

    //主键删除-> 根据菜品id从dish表中删除
    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    //根据分类id统计菜品数量->查询当前分类id下是否还有菜品
    @Select("select count(*) from dish where category_id = #{categoryId}")
    int countByCategoryId(Long categoryId);
}
